const mongoose = require("mongoose");

module.exports.addApply = async apply => {
    return await mongoose.model("applyModel").create(apply);
}

module.exports.getApply = async _id =>{
    return await mongoose.model("applyModel").find(_id)
    .populate("shopId")
    .populate("adminId")
}

module.exports.getApplyByShopid = async shopId =>{
    return await mongoose.model("applyModel").find(shopId)
}

//驳回修改状态为status:3； 同意修改状态为status:2
module.exports.updateApplyById = async (msg) => {
    const { _id, status } = msg
    return await mongoose.model("applyModel").updateOne({ _id } ,{ status })
}

module.exports.deleteApplysById = async _id => {
    return await mongoose.model("applyModel").deleteOne(_id);
}

module.exports.updateApplyStatus = async (applyStatus) => {
    const { _id } = applyStatus
    for (const key in applyStatus) {
        if (applyStatus[key]) {
            return await mongoose.model("applyModel").updateOne({ _id }, applyStatus);
        }
    }
}
